<?php

use Biz\model\ShopCarouselBanner as mShopCarouselBanner;
use Biz\service\CarouselBanner as sCarouselBanner;

/**
 * @deprecated
 */
class FetchAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;

    public function main()
    {
        $posId = $this->getRequest()->getQuery('pos_id', 0);
        $bannerType = $this->getRequest()->getQuery('banner_type', 0);
        if ($posId) {
            switch ($posId) {
                case 12:
                    $bannerType = mShopCarouselBanner::TYPE_ORDER_CONFIRM;//确认订单页
                    break;
                case 13:
                    $bannerType = mShopCarouselBanner::TYPE_ORDER_LIST;//我的订单页
                    break;
                case 14:
                    $bannerType = mShopCarouselBanner::TYPE_ORDER_CART;//购物车
                    break;
            }
        }
        if (intval($bannerType) == mShopCarouselBanner::TYPE_ORDER_CART) {
            $bannerType = [mShopCarouselBanner::TYPE_ORDER_CART, mShopCarouselBanner::TYPE_CART_SUSPENSION];//购物车banner 和悬浮框
        }
        $result = ['banner' => null, 'suspend_icon' => null];
        if ($bannerType) {
            $res = sCarouselBanner::fetchBanner($bannerType);
            if($res) {
                foreach ($res as $type => $info) {
                    if ($type == mShopCarouselBanner::TYPE_CART_SUSPENSION) {
                        $result['suspend_icon'] = $info;
                    } else {
                        $result['banner'] = $info;
                    }
                }
            }
        }
        $this->setSuccess($result);
    }
}